<div class="breadcrumb">
    <ul id="breadcrumb">
        <li><a href="<?php echo Configure::read('base_url');?>backstage" title="Home">
		<?php echo $this->Html->image("home.png", array("alt" => "Home",'class'=>'home','border'=>'0'));?>
		</a></li>
        <li><a href="<?php echo Configure::read('base_url');?>backstage/products/featured" title="product tracking">Products Tracking - Featured</a></li>
    </ul>
</div>
<?php echo $this->element('admin/admin_leftmenu'); ?>
<div id="left">
    <?php
    echo $this->Session->flash();
    if ($this->Session->check('Message.auth'))
        echo $this->Session->flash('auth');
    ?>
    <div class="div_header"><?php __('Products Tracking - Featured'); ?></div>
    <div class="div_content">
        <div class="paging">
            <?php echo $this->element('admin/product/top_menu'); ?>
	</div>
        <div >
            <div  style="width:690px; background:  #ccc; margin-top: 5px; padding: 5px;color: black;">Search</div>
             <div >
           <form method="post" id="searchfrm" action="<?php echo Configure::read('base_url')."backstage/products/featured"; ?>">
<table width="70%" border="0" cellspacing="0" cellpadding="0">
<tr>
    <td  style="border:0px;text-align: right;">Search By:</td><td   style="border:0px; width: 50px; text-align: left;">
        <input type="text" size="36"  id="serchkey" name="serchkey" class="anyOnerequired" title="Please enter keyword." value="Enter Product Item #, Title or Seller ID" onfocus="if(this.value=='Enter Product Item #, Title or Seller ID'){this.value=''}" onblur="if(this.value==''){this.value='Enter Product Item #, Title or Seller ID'}"/>
</td><td  style="border:0px;"><select name="data[type]">
    <option value="item">Item #</option>
    <option value="title">Title</option>
    <option value="sellerid">Seller ID</option>
</select><input type="submit" style="background:#73AE0B;
color:#fff; font-size:14px;" name="button" id="button" value="Search" />
</td>
</tr>
</table>
</form>
  <div id='message_success'></div>
         </div>
            </div>
<input type="button" class="make_featured" value="Make Featured" name="Make Selected Featured" />&nbsp;
<input type="button" class="remove_featured" value="Remove Featured" name="Remove Selected From Featured" />&nbsp;
           <table id="category_table" cellspacing="0" class="tablesorter">
            <thead>
               <tr style="background:gray;">
			<th><input type="checkbox" id="select_all" /></th>
			<th>&nbsp;</th>
			<th>Item #</th>
			<th>Title</th>
			<th>Seller</th>
			<th>Featured Status</th>
<!--                        <th>Approval Date</th>
                        <th>Approval By</th>-->
			<th class="actions"><?php __('Actions');?></th>
	</tr>
            </thead>
            <tbody>
                <?php
               if(!empty ($products)){
                $i = 0;
               //pr($products);

                foreach ($products as $product):
//pr($product);                  
				  $class = null;
                    if ($i++ % 2 == 0) 
                    $class = ' class="alt"';
                    
                ?>
                                  
                    <tr class="fullrow<?php echo $product['Product']['id']; ?>">
                    <td><input type="checkbox" id="products_id" value="<?php echo $product['Product']['id']; ?>" /></td>
                    <td <?php echo $class;?>  style="vertical-align: middle;">
						<?php 
						$image="thumbs/";
						if($product['Product']['products_thumbnailImage']!=""){
							echo $html->image('thumbs/'.$thumbnail->render($product['Product']['products_thumbnailImage'],
				                array(
				                    'path'=>'thumbs',
				                    'width'=>140,
				                    'height'=>140,
				                    'quality'=>80
				                )
				            ),array('alt'=>$product['Product']['products_title'],'class'=>'shuffle','width'=>80)
				        );
                  		
				       
						}?>
						</td>
                    <td <?php echo $class;?>  style="vertical-align: middle;">
                     <?php echo $product['Product']['id']; ?>
                    </td>
                    <td  <?php echo $class;?>  style="vertical-align: middle;"><?php echo $product['Product']['products_title']; ?></td>
                    <td <?php echo $class;?>  style="vertical-align: middle;"><?php echo $product['User']['username']; ?></td>
                    <td <?php echo $class;?> style="vertical-align: middle;"> <?php echo $product['Product']['featured']; ?></td>
<!--                    <td <?php //echo $class;?> style="vertical-align: middle;">
                     <?php //echo date('d/m/Y',  strtotime($product['Product']['approved_date'])); ?>
                    </td>
                    <td  <?php //echo $class;?> style="vertical-align: middle;">
                    <?php //echo $product['Approver']['username']; ?></td>-->
        <td align="center"  <?php echo $class;?> style="vertical-align: middle;">
         <?php if($product['Product']['featured']=="Pending"){?>
        <a href="<?php echo $this->Html->url(array("controller" => "products","action" => "featured",2,$product['Product']['id'],'admin'=>false));?>">Approved featured</a> <br>
        <?php }if($product['Product']['featured']=="Yes"){?>
        <a href="<?php echo $this->Html->url(array("controller" => "products","action" => "featured",0,$product['Product']['id'],'admin'=>false));?>">Remove featured</a> <br>
        <?php }?>
        </td>
             </tr>
               
        <?php
        $comments = $this->requestAction('/products/getnote/'.$product['Product']['id'].'/'.$product['Product']['user_id'].'/'.'1');
        //pr($comments);
        if(!empty ($comments)){
?>
       <tr    class="fullrow<?php echo $product['Product']['id']; ?>">
            <td colspan="8" id="disnote<?php echo $product['Product']['id']; ?>" style="background: none repeat scroll 0pt 0pt BlanchedAlmond;">
    <?php
        
        foreach($comments as $comment) {
        echo '<b>'.$comment['User']['username'].' [ '.date('d-m-Y g:i A',  strtotime($comment['Note']['created'])).' ] : </b> '.$comment['Note']['note'];echo"<br/>";
        //$j++;

        }
?>
</td></tr>
        <?php
        }
        ?>
<?php 
                        endforeach;
               }else{
                   ?>
        <tr>
         <td colspan="8">
             No Product Found.
             </td>
        </tr>
       <?php
               }
                        ?>
                    <tbody>
                </table>
<input type="button" class="make_featured" value="Make Featured" name="Make Selected Featured" />&nbsp;
<input type="button" class="remove_featured" value="Remove Featured" name="Remove Selected From Featured" />&nbsp;
        <div class="paging">
		<?php
                if($type!=null){
                $paginator->options(array('url' => "$serchkey/$type"));
                }
                echo $this->Paginator->prev('<< ' . __('previous', true), array(), null, array('class'=>'disabled'));?>
	 | 	<?php echo $this->Paginator->numbers();?>
 |
		<?php echo $this->Paginator->next(__('next', true) . ' >>', array(), null, array('class' => 'disabled'));?>
	</div>
            </div>
            <div class="div_bottom"></div>
        </div>
        <!-- edit sidebar items here -->
        </div>
<?php echo $html->script(array("jquery.pagination.js", "jquery.tablesorter.min.js", "jquery.tablednd.js","jquery.validate.js")); ?>
<script type="text/javascript"> 
 
    jQuery(document).ready(function(){
        jQuery("#category_table").tablesorter({headers: {0:{sorter: false},1:{sorter: false}, 5:{sorter: false}, 6:{sorter: false}}});

         jQuery.validator.addMethod("anyOnerequired", function (value, element) {
             var serchkey=jQuery("#serchkey").val();

          if(serchkey=='' || serchkey=='Enter Product Item #, Title or Seller ID'){return false;}else{return true;}


    }, "This field is required.");

 var v = jQuery("#searchfrm").validate({

                       });
 jQuery("#select_all").click(function(){
        var checked_status = this.checked;
        jQuery("input[id=products_id]").each(function()
        {
            //var mid=jQuery(this).val();
            this.checked = checked_status;
        });
    });
jQuery(".make_featured").click(function(){
    var data=new Array();
	var flag=true;
        jQuery("input[id=products_id]").each(function(index)
        {
            var checked_status=this.checked;
            if(checked_status==true){
                var mid=jQuery(this).val();
				data[index] = mid;
            }
        });
        if(data){
			url = baseurl+"products/makefeatured/";
			jQuery.post(url, { 'pid[]' : data},function(data) {
			  window.location = baseurl+'backstage/products/featured';
			});

		}
		else{alert("You have to select product to make featured");}
});
jQuery(".remove_featured").click(function(){
    var data=new Array();
	var flag=true;
        jQuery("input[id=products_id]").each(function(index)
        {
            var checked_status=this.checked;
            if(checked_status==true){
                var mid=jQuery(this).val();
				data[index] = mid;
            }
        });
        if(data){
			url = baseurl+"products/remove_featured/";
			jQuery.post(url, { 'pid[]' : data},function(data) {
			  window.location = baseurl+'backstage/products/featured';
			});

		}
		else{alert("You have to select product to make featured");}
});
 });
</script>